#include<iostream>
//2
class Test
{
public:
    Test()
    {
        std::cout<<"构建函数\n";
    }
    ~Test()
    {
        std::cout<<"析构函数\n";
    }

};
class Derived:public Test
{

};
void func()
{
    //Test t;//栈的解旋:函数栈上的临时对象会在抛出异常前全部释放
    throw Derived();
}
int main()
{
    try
    {
        func();
    }
    //支持向上转型
    //当多个分支都能捕获时，按顺序捕获
    catch(const Test&t)//捕获的对象会在catch之后释放
    {
        std::cout<<"error!\n";
    }
    catch(const Derived&t)
    {
        std::cout<<"Derived!\n";
    }



    return 0;
}